package com.accp.biz.impl;

import com.accp.biz.ComputerBiz;
import com.accp.dao.ComputerDao;
import com.accp.pojo.Computer;

import java.util.List;

public class ComputerBizImpl implements ComputerBiz {

    private ComputerDao computerDao;

    public void setComputerDao(ComputerDao computerDao) {
        this.computerDao= computerDao;
    }

    @Override
    public boolean delete(int id) {
       int a=this.computerDao.delete(id);
        if(a==0){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public boolean add(Computer computer) {
        int a=this.computerDao.add(computer);
        if(a==0){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public boolean update(Computer computer) {
        int a=this.computerDao.update(computer);
        if(a==0){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public Computer findById(Integer id) {
        return this.computerDao.findById(id);
    }

    @SuppressWarnings("rawtypes")
    @Override
    public List selectByName(String className, String dname) {
        return computerDao.selectByName(className,dname);
    }

    @SuppressWarnings("rawtypes")
    @Override
    public List selectByPage(String className, int pageNo, int pageSize) {
        List list = computerDao.selectByPage(className, pageNo, pageSize);
        return list;
    }

    @Override
    public int searchRecordsNextPage(int pageSize, String className) {
        int total = computerDao.totalPage(className);
        int pageNo = total / pageSize;
        if(total % pageSize > 0){
            pageNo++;
        }
        return pageNo;
    }

}
